import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import departmentsAsyncRoute from '@/router/modules/departments'
import employessAsyncRoute from '@/router/modules/employess'
import settingsAsyncRoute from '@/router/modules/settings'
import salarysAsyncRoute from '@/router/modules/salarys'
import socialAsyncRoute from '@/router/modules/social'
import attendancesAsyncRoute from '@/router/modules/attendances'
import approvalsAsyncRoute from '@/router/modules/approvals'
import permissionAsyncRoute from '@/router/modules/permission'
//动态路由表需要权限，根据权限动态生成
export const asyncRoutes=[
  departmentsAsyncRoute,
  settingsAsyncRoute,
  employessAsyncRoute,
  permissionAsyncRoute,
  approvalsAsyncRoute,
  attendancesAsyncRoute,
  salarysAsyncRoute,
  socialAsyncRoute,
]
  //存放动态路由的




//填写路由规则
//静态路由表,不需要权限谁都可以看
export const constantRoutes = [
  {
    path: '/import',
    component: () => import('@/views/import/index'),
    hidden: true
  },
  // {
  //   path: '/demo',
  //   component: () => import('@/views/demo/index.vue'),
  //   hidden: true
  // },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]//将动态路由表和静态路由表合并一起,生成最终的路由表
})

const router = createRouter()

//重置路由的方法
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
